package modele;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

/**
 *
 * @author Danicela
 */
public class Resultat
{

    private int id;
    private Date date;
    private String texte;
    private Echantillon echantillon;
    private Analyse analyse;

   public Resultat(int id, Date date, String texte, Echantillon echantillon, Analyse analyse) {
        this.id = id;
        this.date = date;
        this.texte = texte;
        this.echantillon = echantillon;
        this.analyse = analyse;
    }

    public int getId()
    {
        return id;
    }

   public Analyse getAnalyse() {
        return analyse;
    }

    public Date getDate() {
        return date;
    }

    public Echantillon getEchantillon() {
        return echantillon;
    }

    public String getTexte() {
        return texte;
    }

    //Accès BD

    public static void enregistrerNouveauResultat(Date date, String texte, int idEchantillon, int idAnalyse) throws SQLException
    {
        String requete = "Insert into resultat(id_analyse, id_echantillon, date, texte) values(?, ?, ?, ?);";
        Connection c = Database.getConnection();
        PreparedStatement ps = c.prepareStatement(requete);
        ps.setInt(1, idAnalyse);
        ps.setInt(2, idEchantillon);
        ps.setDate(3, new java.sql.Date(date.getTime()));
        ps.setString(4, texte);

        ps.executeUpdate();

        c.close();
    }



}
